package utils;

import java.util.Iterator;

public class TriangleIterator implements Iterator<Integer> {
	int count = 1;
	int sum = 0;
	
	@Override
	public boolean hasNext() {
		return true;
	}

	@Override
	public Integer next() {
		sum += count++;
		if (sum < 0) {
			throw new IllegalStateException("Overflow!");
		}
		return sum;
	}

	@Override
	public void remove() {
		throw new UnsupportedOperationException();
	}
}
